/*
 * Copyright (c) novafaen design 2009 
 */
package tentaflykt.util;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

/**
 * Utility class for simpler use of <code>GridBagConstraint</code>.
 * @author Kristoffer Nilsson
 */
public class GBC {
  /**
   * Anchor placements.
   */
  public interface Anchor {
    /** Anchor in objects top left corner */
    public static final int TOP_LEFT     = GridBagConstraints.NORTHWEST;
    /** Anchor in objects top right corner */
    public static final int TOP_RIGHT    = GridBagConstraints.NORTHEAST;
    /** Anchor in objects bottom left corner */
    public static final int BOTTOM_LEFT  = GridBagConstraints.SOUTHWEST;
    /** Anchor in objects bottom right corner */
    public static final int BOTTOM_RIGHT = GridBagConstraints.SOUTHEAST;
  }
  
  /**
   * Filling rules.
   */
  public interface Fill {
    /** Horizontal fill */
    public static final int HORIZONTAL = GridBagConstraints.HORIZONTAL;
    /** Vertical fill */
    public static final int VERTICAL   = GridBagConstraints.VERTICAL;
    /** Both horizontal and vertical fill */
    public static final int BOTH       = GridBagConstraints.BOTH;
    /** No filling */
    public static final int NONE       = GridBagConstraints.NONE;
  }
  
  /**
   * Creates a <code>GridBagConstraints</code> object.
   * @param posX Horizontal grid position
   * @param posY Vertical grid position
   * @param width The objects width
   * @param height The objects height
   * @param weightX Grid horizontal weight
   * @param weightY Grid vertical weight
   * @param anchor The objects anchor
   * @param fill Horizontal and vertical filling
   * @param top The top margin
   * @param left The left margin
   * @param bottom The bottom margin
   * @param right The right margin
   * @return <code>GridBagConstraints</code> object
   */
  public static GridBagConstraints use(int posX, int posY, int width, int height, 
      double weightX, double weightY, int anchor, int fill, 
      int top, int left, int bottom, int right) {
    // create without paddings
    return new GridBagConstraints(posX, posY, width, height, 
        weightX, weightY, anchor, fill, 
        new Insets(top, left, bottom, right), 0, 0);
  }
  
  /**
   * Creates a default <code>GridBagConstraints</code> to eat up empty space.
   * Should be placed under and to the right of most south east object.
   * @param posX Horizontal grid position
   * @param posY Vertical grid position
   * @return <code>GridBagConstraints</code> object
   */
  public static GridBagConstraints spaceEater(int posX, int posY) {
    return new GridBagConstraints(posX, posY, 1, 1, 
        1.0, 1.0, Anchor.TOP_LEFT, Fill.BOTH, 
        new Insets(0, 0, 0, 0), 0, 0);
  }
  
  /**
   * Called to set the current layout to <code>GridBadLayout</code>.
   * @return <code>GridBagLayout</code> object
   */
  public static GridBagLayout gbcLayout() {
    return new GridBagLayout();
  }
}